package com.njitzx.controller;


import com.njitzx.entity.po.Permission;
import com.njitzx.entity.vo.PermVO;
import com.njitzx.service.PermissionService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.njitzx.entity.vo.Result;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

import lombok.RequiredArgsConstructor;


import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author 周鑫
 * @since 2024-08-20
 */
@Api(tags = "权限表接口")
@RestController
@RequestMapping("/rights")
@RequiredArgsConstructor
public class PermissionController {

    private final PermissionService permissionService;

//    @ApiOperation("权限表分页查询")
//    @GetMapping("/list")
//    public Result findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") Integer pageNum,
//                           @ApiParam("页大小") @RequestParam(defaultValue = "5") Integer pageSize,
//                           @ApiParam("查询条件") Permission permission) {
//        PageInfo<Permission> pageInfo = permissionService.findPage(pageNum, pageSize, permission);
//        return Result.success(pageInfo);
//    }

//    @ApiOperation("根据主键查询权限表")
//    @GetMapping("/{psId}")
//    public Result findById(@PathVariable Serializable psId) {
//        return Result.success(permissionService.findById(psId));
//    }

    @ApiOperation("新增权限表")
    @PostMapping
    public Result add(@RequestBody Permission permission) {
        permissionService.add(permission);
        return Result.success();
    }

    @ApiOperation("修改权限表")
    @PutMapping
    public Result modify(@RequestBody Permission permission) {
        permissionService.modify(permission);
        return Result.success();
    }

    @ApiOperation("根据主键删除权限表")
    @DeleteMapping("/{psId}")
    public Result removeById(@PathVariable Serializable psId) {
        permissionService.removeById(psId);
        return Result.success();
    }

    @ApiOperation("所有权限列表")
    @GetMapping("/{type}")
    public Result findAllPermission(@PathVariable String type) {
        List<PermVO> permVOS = permissionService.findAll(type);
        return Result.success(permVOS);
    }

}
